// pages/user/historical/historical.js
import { queryInvoiceList } from '../../../api/invoice.js'
const date= require('../../../utils/Date.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    date: '2020-01-01',//默认起始时间  
    date2: '2020-12-30',//默认结束时间 
    invoiceList:'',
    name:0,
    active:0
  },
  // 时间段选择  
  bindDateChange(e) {
    let that = this;
    that.setData({
      date: e.detail.value,
    })
    that.querylist()
  },
  bindDateChange2(e) {
    let that = this;
    that.setData({
      date2: e.detail.value,
    })
    that.querylist()
  },
  querylist(){
    const dataParams = {
      'status': this.data.active,
      'dateBegin': this.data.date,
      'dateEnd': this.data.date2
    }
    queryInvoiceList(dataParams).then(res => {
      for (var i = 0; i < res.length; i++) {
        res[i].createDate = date.formatDate(res[i].createDate).substring(0, 10)
      }
      console.log(res)
      this.setData({
        invoiceList: res
      })

    })
  },
  onClick: function (event){
    console.log(event)
   this.setData({
     active:event.detail.name
   })
    const dataParams = {
      'status': event.detail.name,
      'dateBegin': this.data.date,
      'dateEnd': this.data.date2
    }  
    queryInvoiceList(dataParams).then(res => {
      for (var i = 0; i < res.length; i++) {
        res[i].createDate = date.formatDate(res[i].createDate).substring(0, 10)
      }  
      console.log(res)
      this.setData({
        invoiceList: res
      })

    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
 
    const dataParams={
      'status': 0,
      'dateBegin': this.data.date,
      'dateEnd': this.data.date2
    }

    queryInvoiceList(dataParams).then(res => {

      for (var i = 0; i < res.length; i++) {
        res[i].createDate = date.formatDate(res[i].createDate).substring(0, 10)
      }
      this.setData({
        invoiceList: res
      })
      console.log(this.invoiceList)
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})